﻿using Kingdee.BOS.Core.CommonFilter.PlugIn;
using Kingdee.BOS.Core.ReportFilter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Model.ReportFilter;
using System.ComponentModel;
using Kingdee.BOS.Util;

namespace RK.ReportPlugin.BPW
{
    [Description("直接SQL账表，插件修改日期默认值为当月第一天和最后一天"), HotUpdate]
    public class SqlReportFilter : AbstractCommonFilterPlugIn
    {
        public override void BeforeBindData(EventArgs e)
        {
            base.BeforeBindData(e);
            SQLReportFilterModel sqlModel = this.Model as SQLReportFilterModel;
            if (sqlModel == null)
            {
                return;
            }
            var sqlfilterFlds = sqlModel.SQLFilterObject.FilterFieldList;
            foreach (var flds in sqlfilterFlds)
            {
                if (flds.KeyWord == "#StartDate#")
                {
                    var firstDay = DateTime.Now.AddDays(1 - DateTime.Now.Day);
                    flds.DefaultValue = firstDay.ToString("yyyy-MM-dd");
                }
                if (flds.KeyWord == "#EndDate#")
                {
                    var endDay = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1);
                    flds.DefaultValue = endDay.ToString("yyyy-MM-dd");
                }
            }
        }
    }
}
